package com.fjut.controller;


import com.fjut.model.vod.Teacher;
import com.fjut.result.Result;
import com.fjut.service.TeacherService;
import com.fjut.vo.vod.TeacherQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author DengTianxun
 * @since 2023-03-02
 */
@Api(tags = "讲师管理接口")
//@CrossOrigin
@RestController
@RequestMapping("/fjut/vod/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @ApiOperation("查询所有讲师")
    @GetMapping("findAll")
    public Result findAllTeacher(){
        return Result.success(teacherService.list());
    }

    @ApiOperation("逻辑删除讲师")
    @DeleteMapping("deleteTeacher/{id}")
    public Result deleteTeacherById(@ApiParam(name = "id", value = "ID", required = true) @PathVariable int id){
        if (teacherService.removeById(id)) {
            return Result.success(true).message("删除成功");
        }else {
            return Result.fail(false).message("删除失败");
        }
    }

    @ApiOperation("条件查询讲师")
    @PostMapping("getTeacherPage/{current}/{limit}")
    public Result getTeacherPage(@PathVariable Long current, @PathVariable Long limit, @RequestBody(required = false) TeacherQueryVo teacherQueryVo){
        return Result.success(teacherService.getTeacherPage(current, limit, teacherQueryVo));
    }

    @ApiOperation("添加或修改讲师信息")
    @PostMapping("saveOrInsertTeacherInfo")
    public Result saveTeacher(@RequestBody Teacher teacher){
        if (teacherService.saveOrUpdate(teacher)) {
            return Result.success(true);
        }else {
            return Result.fail(false);
        }
    }

    @ApiOperation("批量删除讲师")
    @DeleteMapping("removeTeacherList")
    public Result removeTeacherList(@RequestBody List<Long> ids){
        if (teacherService.removeByIds(ids)) {
            return Result.success(true).message("删除成功");
        }else {
            return Result.fail(false).message("删除失败");
        }
    }

    @ApiOperation("远程调用查询单个讲师信息")
    @GetMapping("getClientTeacherInfoById/{id}")
    public Teacher getClientTeacherInfoById(@PathVariable("id") Long id){
        return teacherService.getById(id);
    }
}

